// import Config from '@/config'
// import SessionStorageModule from "@/tools/sessionStorage";
import UserTokenModule from '@/tools/token'
import RouterViewMenusModule from "@/tools/vital/menus_data"
export default {
    // 添加路由到面包屑
    PUSH_BREADCRUMB_ROUTER(state, data) {
        state.BreadcrumbList.push(data)
    },
    // 删除面包屑单个路由
    DELETE_BREADCRUMB_ROUTER(state, data) {
        let { id, path } = data
        let itemIndex = state.BreadcrumbList.findIndex(item => item.meta.id == id || item.path == path)
        if (itemIndex != -1) {
            state.BreadcrumbList.splice(itemIndex, 1)
        }
    },
    // 清空面包屑所有路由
    EMPTY_Breadcrumb_ALL_ROUTER(state) {
        state.BreadcrumbList = []
    },
    // 设置路由祖先ID
    SET_ROUTER_ANCESTOR_ID(state, data) {
        let { id } = data
        state.CurrentRouterAncestorId = id
    },
    // 设置路由跳转前To对象
    SET_ROUTER_TO_INFO(state, data) {
        state.BeforeEachRouterToInfo = data
    },
    // 设置路由跳转前form对象
    SET_ROUTER_FORM_INFO(state, data) {
        state.BeforeEachRouterFormInfo = data
    },
    // 展开菜单列表
    SET_ROUTER_MENU_LIST_OPEN_STATUS(state, data) {
        let { status, id } = data
        let menusIndex = state.RouterOriginList.findIndex((item) => item.meta.id == id)
        state.RouterOriginList[menusIndex].meta.display.childrenDevelop = Boolean(status)
    },

    // 设置登录等待状态
    SET_LOGIN_LOADING_STATUS(state, status) {
        state.loginLoading = Boolean(status)
    },
    // 设置路由源数据数组列表
    SetRouterOriginList(state, MenusListData) {
        state.RouterOriginList = MenusListData
        RouterViewMenusModule.SetMenusList(MenusListData)
    },
    // 切换当前图标导航栏所选菜单ID
    SetIconNavigatorCurrentId(state, data) {
        let { id } = data
        let currentId = state.currentIconNavigatorId
        let newId = id
        if (newId != currentId) {
            state.currentIconNavigatorId = id
        }
    },
    // 即将进入路由
    BEFORE_ENTER_ROUTER(state, data) {
        let { id } = data
        state.before_enter_route_id = id
    },
    // 进入路由页面
    ENTER_ROUTER(state, data) {
        let { id } = data
        let RouterInfo = state.RouterOriginList.find(item => item.meta.id == id)
        console.log("RouterInfo", RouterInfo);
        if (RouterInfo) {
            state.CurrentRouterInfo = RouterInfo
        }
        let currentId = state.currentNavigatorId
        if (id != currentId) {
            state.currentNavigatorId = id
        }
    },
    // 切换全屏状态
    changeDocumentFullScreenStatus(state) {
        const current = state.documentFullScreen
        if (current) {
            if (document.exitFullscreen) {
                document.exitFullscreen();
            } else if (document.msExitFullscreen) {
                document.msExitFullscreen();
            } else if (document.mozCancelFullScreen) {
                document.mozCancelFullScreen();
            } else if (document.webkitExitFullscreen) {
                document.webkitExitFullscreen();
            }
        } else {
            let element = document.documentElement;
            if (element.requestFullscreen) {
                element.requestFullscreen();
            } else if (element.mozRequestFullScreen) {
                element.mozRequestFullScreen();
            } else if (element.msRequestFullscreen) {
                element.msRequestFullscreen();
            } else if (element.webkitRequestFullscreen) {
                element.webkitRequestFullScreen();
            }
        }
        const changeStatus = !current
        state.documentFullScreen = changeStatus
    },
    // 设置系统自定义配置项数据
    setSystemCustomOriginData(state, CustomData) {
        state.setting = CustomData
    },
    // 修改系统自定义配置项数据
    updateCustomSettingValue(state, data) {
        let {
            GroupKey,
            settingKey,
            newValue
        } = data
        let GroupObject = state.setting[GroupKey]
        // 判断配置组状态是否正常
        let GroupStatus = GroupObject?.status || false
        if (!GroupStatus) {
            console.log("修改配置项失败,配置组状态异常");
            return
        }
        // 判断配置组是否允许更新
        let GroupUpdate = GroupObject?.update || true
        if (!GroupUpdate) {
            console.log("修改配置项失败,配置组不允许更新");
            return
        }
        // 获取配置组下的配置项对象
        let GroupSettingObject = GroupObject?.setting
        if (!GroupSettingObject) {
            console.log("修改配置项失败,配置组中配置项对象类型异常");
            return
        } else if (Object.prototype.toString.call(GroupSettingObject) != "[object Object]") {
            console.log("修改配置项失败,配置组中配置项对象类型异常");
            return
        }
        let SettingItemObject = GroupSettingObject[settingKey]
        // 配置项数据类型
        let SettingItemType = SettingItemObject.type
        // 配置项原value
        let SettingItemValue = SettingItemObject.value
        if (SettingItemValue === newValue) {
            return
        }
        if (SettingItemType === "switch" || SettingItemType === 0) {
            state.setting[GroupKey].setting[settingKey].value = Boolean(newValue)
        } else if (SettingItemType === "select" || SettingItemType === 1) {
            state.setting[GroupKey].setting[settingKey].value = Number(newValue)
        } else if (SettingItemType === "input" || SettingItemType === 2) {
            state.setting[GroupKey].setting[settingKey].value = newValue
        } else {
            console.log("修改配置项失败,配置项类型不支持修改");
            return
        }


    },
    // 设置某个菜单项获取焦点
    SetMenuItemFocus(state, data) {
        let { id } = data
        console.log({ state, id });
    },

    // 菜单设置消息点
    SetMenuBuoy(state, data) {
        let { id, value } = data
        console.log({ state, id, value });
    },
    // 菜单消息点+1
    MenuBuoyAdd(state, data) {
        let { id, value } = data
        console.log({ state, id, value });
    },
    // 菜单消息点-1
    MenuBuoyReduce(state, data) {
        let { id, value } = data
        console.log({ state, id, value });
    },
    // 菜单消息点清空
    MenuBuoyEmpty(state, data) {
        let { id, value } = data
        console.log({ state, id, value });

    },
    // 打开消息弹出层
    openMessageBoxPopup(state) {
        console.log("触发打开消息");
        state.messagePopupShow = true
    },
    // 关闭消息弹出层
    closeMessageBoxPopup(state) {
        console.log("触发关闭消息");
        state.messagePopupShow = false
    },
    // 切换消息弹出层状态
    changeMessageBoxPopupStatus(state) {
        let current = state.messagePopupShow
        let changeStatus = !current
        state.messagePopupShow = changeStatus
    },
    // 打开颜色配置弹出层
    openColorMatchingPopup(state) {
        state.colorMatching = true
    },
    // 关闭颜色配置弹出层
    closeColorMatchingPopup(state) {
        state.colorMatching = false
    },
    // 切换颜色配置弹出层状态
    changeColorMatchingPopupStatus(state) {
        let current = state.colorMatching
        let changeStatus = !current
        state.colorMatching = changeStatus
    },
    // 打开页面顶部用户信息鼠标选项菜单显示状态
    openHeaderUserInfoMouseOptions(state) {
        state.userInfoMouseOptionsShow = true
    },
    // 关闭页面顶部用户信息鼠标选项菜单显示状态
    closeHeaderUserInfoMouseOptions(state) {
        state.userInfoMouseOptionsShow = false
    },
    // 修改页面顶部用户信息鼠标选项菜单显示状态
    changeHeaderUserInfoMouseOptionsStatus(state) {
        let current = state.userInfoMouseOptionsShow
        let changeStatus = !current
        state.userInfoMouseOptionsShow = changeStatus
    },
    // 修改路由过度动画
    changeRouterViewTransitionName(state, data) {
        state.routerViewTransitionName = data
    },
    // 设置路由框加载状态
    SET_ROUTERVIEW_LOADING(state, data) {
        state.routerViewLoading = data
    },
    // 清除页面所有弹出
    clickRouterView(state) {
        let { messagePopupShow, userInfoMouseOptionsShow } = state
        if (messagePopupShow) {
            state.messagePopupShow = false
        }
        if (userInfoMouseOptionsShow) {
            state.userInfoMouseOptionsShow = false
        }
    },
    // 重置登录用户信息
    resetUserInfo(state) {
        console.log(state);
    },
    // 设置登录用户信息
    SET_LOGIN_USER_INFO(state, info) {
        let { avatar, username } = info

        let defaultAvatarUrl = "https://img1.baidu.com/it/u=1233436729,3465492660&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800"

        state.userInfo.avatar = avatar ?? defaultAvatarUrl;
        state.userInfo.username = username
    },
    // 存储Tokne
    SET_LOGIN_TOKEN(state, tokenInfo) {
        // 取出传入参数
        let { token, tokenExpire } = tokenInfo
        // 存储到VueX
        state.token = token
        UserTokenModule.SetUserToken({
            token, tokenExpire
        })
    },
    // 退出登录
    Sign_LOGIN(state) {
        // 置空当前选择的图标菜单栏选择ID
        state.currentIconNavigatorId = null
        // 清空当前选择的侧边菜单栏选择ID
        state.currentNavigatorId = null
        // 清空当前选择的路由对象信息
        state.CurrentRouterInfo = {}
        // 取消登录等待状态
        state.loginLoading = false
        // 清空VueX存储的路由菜单信息
        state.RouterOriginList = []
        // 清空本地存储的路由菜单信息
        RouterViewMenusModule.EmptyMenusList()
        // 清空VueX存储的用户token
        state.token = null
        // 清空本地存储的用户token
        UserTokenModule.removeToken()
        // 清空以登录用户信息
        state.userInfo.avatar = null
        // 清空用户名
        state.userInfo.username = null

    }
}